public class test2 {
    class Solution {
        public boolean isPalindrome(String s) {
            StringBuilder sb = new StringBuilder();
            for(int i = 0;i<s.length();i++){
                if(Character.isLetter(s.charAt(i)) || Character.isDigit(s.charAt(i))){
                    sb.append(s.charAt(i));
                }
            }
            String str = sb.toString();
            return isValid(str);
        }
        private boolean isValid(String str){
            int left = 0,right = str.length()-1;
            while(left<right){
                if(str.charAt(left)!=str.charAt(right) && str.charAt(left)!=Character.toLowerCase(str.charAt(right)) && str.charAt(right)!=Character.toLowerCase(str.charAt(left))){
                    return false;
                }
                left++;
                right--;
            }
            return true;
        }
    }
}
